/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pv168.uloha3.swing;

import cz.muni.fi.pv168.uloha3.swing.workers.OwnershipRemoveSwingWorker;
import cz.muni.fi.pv168.uloha3.swing.workers.EstateEditSwingWorker;
import cz.muni.fi.pv168.uloha3.swing.workers.EstateAddSwingWorker;
import cz.muni.fi.pv168.uloha3.swing.workers.EstateDeleteSwingWorker;
import cz.muni.fi.pv168.uloha3.swing.workers.OwnerAddSwingWorker;
import cz.muni.fi.pv168.uloha3.swing.workers.OwnerDeleteSwingWorker;
import cz.muni.fi.pv168.uloha3.swing.workers.OwnerEditSwingWorker;
import cz.muni.fi.pv168.uloha3.swing.workers.OwnershipListSwingWorker;
import java.awt.Color;
import java.util.Locale;
import javax.swing.JOptionPane;

/**
 *
 * @author morty
 */
public class SwingGuiMain extends javax.swing.JFrame {

    //private Locale localization = Locale.getDefault();
    private Locale localization = new Locale("cs", "CZ");
    /**
     * Creates new form SwingGuiMain
     */
    public SwingGuiMain() {
        initComponents();
        this.setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane4 = new javax.swing.JTabbedPane();
        jPanelOwners = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTableOwners = new javax.swing.JTable();
        jButtonDeleteOwner = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabelOwnerName = new javax.swing.JLabel();
        jTextOwnerFieldName = new javax.swing.JTextField();
        jLabelOwnerSurname = new javax.swing.JLabel();
        jTextOwnerFieldSurname = new javax.swing.JTextField();
        jLabelOwnerSSN = new javax.swing.JLabel();
        jTextOwnerFieldSSN = new javax.swing.JTextField();
        jLabelOwnerAddress = new javax.swing.JLabel();
        jTextOwnerFieldAddress = new javax.swing.JTextField();
        jLabelOwnerTelephone = new javax.swing.JLabel();
        jTextOwnerFieldOwnerTelephone = new javax.swing.JTextField();
        jButtonOwnerSave = new javax.swing.JButton();
        jLabelOwnerNameErr = new javax.swing.JLabel();
        jLabelOwnerSurnameErr = new javax.swing.JLabel();
        jLabelOwnerSsnErr = new javax.swing.JLabel();
        jTextOwnerFieldId = new javax.swing.JTextField();
        jButtonClearOwnerForm = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jButtonOwnerEstatesAdd = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableOwnerEstates = new javax.swing.JTable();
        jButtonRemoveUserOwnership = new javax.swing.JButton();
        jPanelEstates = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabelEstateCatastralID = new javax.swing.JLabel();
        jTextFieldEstateCatastralID = new javax.swing.JTextField();
        jLabelEstateAddress = new javax.swing.JLabel();
        jTextFieldEstateAddress = new javax.swing.JTextField();
        jLabelEstateType = new javax.swing.JLabel();
        jComboBoxEstateType = new javax.swing.JComboBox();
        jButtonEstateSave = new javax.swing.JButton();
        jButtonClearEstateForm = new javax.swing.JButton();
        jLabelEstateCatastralIDErr = new javax.swing.JLabel();
        jLabelEstateAddressErr = new javax.swing.JLabel();
        jTextFieldEstateId = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTableEstates = new javax.swing.JTable();
        jButtonDeleteEstate = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jButtonEstateOwnersAdd = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableEstateOwners = new javax.swing.JTable();
        jButtonRemoveEstateOwnership = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItemQuit = new javax.swing.JMenuItem();
        jMenuAbout = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization); // NOI18N
        setTitle(bundle.getString("REAL ESTATE MANAGER")); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), bundle.getString("ALL OWNERS"))); // NOI18N

        jTableOwners.setModel(new OwnersTableModel());
        jTableOwners.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableOwners.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableOwnersMouseClicked(evt);
            }
        });
        jTableOwners.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTableOwnersFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTableOwnersFocusLost(evt);
            }
        });
        jScrollPane3.setViewportView(jTableOwners);

        jButtonDeleteOwner.setEnabled(false);
        jButtonDeleteOwner.setText(bundle.getString("DELETE")); // NOI18N
        jButtonDeleteOwner.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDeleteOwnerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButtonDeleteOwner))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonDeleteOwner)
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), bundle.getString("ADD EDIT OWNER"))); // NOI18N

        jLabelOwnerName.setText(bundle.getString("NAME")); // NOI18N

        jTextOwnerFieldName.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextOwnerFieldNameMouseClicked(evt);
            }
        });
        jTextOwnerFieldName.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextOwnerFieldNameInputMethodTextChanged(evt);
            }
        });
        jTextOwnerFieldName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextOwnerFieldNameKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextOwnerFieldNameKeyTyped(evt);
            }
        });

        jLabelOwnerSurname.setText(bundle.getString("SURNAME")); // NOI18N

        jTextOwnerFieldSurname.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextOwnerFieldSurnameKeyPressed(evt);
            }
        });

        jLabelOwnerSSN.setText(bundle.getString("SSN")); // NOI18N

        jLabelOwnerAddress.setText(bundle.getString("ADDRESS")); // NOI18N

        jTextOwnerFieldAddress.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextOwnerFieldAddressActionPerformed(evt);
            }
        });

        jLabelOwnerTelephone.setText(bundle.getString("TELEPHONE")); // NOI18N

        jButtonOwnerSave.setText(bundle.getString("SAVE")); // NOI18N
        jButtonOwnerSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOwnerSaveActionPerformed(evt);
            }
        });

        jLabelOwnerNameErr.setText(" ");
        jLabelOwnerNameErr.setIconTextGap(1);

        jLabelOwnerSurnameErr.setText(" ");

        jLabelOwnerSsnErr.setText(" ");

        jTextOwnerFieldId.setVisible(false);

        jButtonClearOwnerForm.setText(bundle.getString("CANCEL")); // NOI18N
        jButtonClearOwnerForm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClearOwnerFormActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelOwnerAddress)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelOwnerSSN)
                            .addComponent(jLabelOwnerName))
                        .addGap(36, 36, 36)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabelOwnerSsnErr, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabelOwnerNameErr, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextOwnerFieldSSN, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                            .addComponent(jTextOwnerFieldName))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabelOwnerSurname)
                                .addGap(18, 18, 18)
                                .addComponent(jLabelOwnerSurnameErr))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabelOwnerTelephone)
                                .addGap(18, 18, 18))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jTextOwnerFieldAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextOwnerFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextOwnerFieldOwnerTelephone)
                    .addComponent(jTextOwnerFieldSurname, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButtonOwnerSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonClearOwnerForm)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelOwnerName)
                    .addComponent(jTextOwnerFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelOwnerSurname)
                    .addComponent(jTextOwnerFieldSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelOwnerNameErr)
                    .addComponent(jLabelOwnerSurnameErr))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelOwnerSSN)
                    .addComponent(jTextOwnerFieldSSN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelOwnerSsnErr)
                    .addComponent(jLabelOwnerTelephone)
                    .addComponent(jTextOwnerFieldOwnerTelephone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelOwnerAddress)
                    .addComponent(jTextOwnerFieldAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextOwnerFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonOwnerSave)
                    .addComponent(jButtonClearOwnerForm))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), bundle.getString("REAL ESTATES FOR SELECTED OWNER"))); // NOI18N

        jButtonOwnerEstatesAdd.setText(bundle.getString("ADD ESTATES")); // NOI18N
        jButtonOwnerEstatesAdd.setEnabled(false);
        jButtonOwnerEstatesAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOwnerEstatesAddActionPerformed(evt);
            }
        });

        jTableOwnerEstates.setModel(new OwnershipsTableModel(true));
        jTableOwnerEstates.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableOwnerEstates.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTableOwnerEstatesFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTableOwnerEstatesFocusLost(evt);
            }
        });
        jScrollPane1.setViewportView(jTableOwnerEstates);

        jButtonRemoveUserOwnership.setText(bundle.getString("REMOVE ESTATE")); // NOI18N
        jButtonRemoveUserOwnership.setEnabled(false);
        jButtonRemoveUserOwnership.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRemoveUserOwnershipActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jButtonRemoveUserOwnership)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonOwnerEstatesAdd))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonOwnerEstatesAdd)
                    .addComponent(jButtonRemoveUserOwnership))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanelOwnersLayout = new javax.swing.GroupLayout(jPanelOwners);
        jPanelOwners.setLayout(jPanelOwnersLayout);
        jPanelOwnersLayout.setHorizontalGroup(
            jPanelOwnersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelOwnersLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelOwnersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelOwnersLayout.setVerticalGroup(
            jPanelOwnersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOwnersLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelOwnersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelOwnersLayout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane4.addTab("Owners", jPanelOwners);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), bundle.getString("ADD EDIT ESTATE"))); // NOI18N

        jLabelEstateCatastralID.setText(bundle.getString("CATASTRAL ID")); // NOI18N

        jLabelEstateAddress.setText(bundle.getString("ADDRESS")); // NOI18N

        jLabelEstateType.setText(bundle.getString("TYPE")); // NOI18N

        jComboBoxEstateType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "House", "Appartment", "Land", "Forest" }));

        jButtonEstateSave.setText(bundle.getString("SAVE")); // NOI18N
        jButtonEstateSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEstateSaveActionPerformed(evt);
            }
        });

        jButtonClearEstateForm.setText(bundle.getString("CANCEL")); // NOI18N
        jButtonClearEstateForm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClearEstateFormActionPerformed(evt);
            }
        });

        jTextFieldEstateId.setVisible(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelEstateCatastralID)
                            .addComponent(jLabelEstateAddress))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabelEstateCatastralIDErr, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelEstateAddressErr, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jLabelEstateType))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTextFieldEstateAddress)
                    .addComponent(jComboBoxEstateType, 0, 168, Short.MAX_VALUE)
                    .addComponent(jTextFieldEstateCatastralID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                .addComponent(jTextFieldEstateId, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonEstateSave)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonClearEstateForm)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelEstateCatastralID)
                    .addComponent(jTextFieldEstateCatastralID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEstateCatastralIDErr))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelEstateAddress)
                    .addComponent(jTextFieldEstateAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEstateAddressErr))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelEstateType)
                    .addComponent(jComboBoxEstateType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonEstateSave)
                    .addComponent(jButtonClearEstateForm)
                    .addComponent(jTextFieldEstateId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), bundle.getString("ALL ESTATES"))); // NOI18N

        jTableEstates.setModel(new EstatesTableModel());
        jTableEstates.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableEstatesMouseClicked(evt);
            }
        });
        jTableEstates.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTableEstatesFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTableEstatesFocusLost(evt);
            }
        });
        jScrollPane5.setViewportView(jTableEstates);

        jButtonDeleteEstate.setText(bundle.getString("DELETE")); // NOI18N
        jButtonDeleteEstate.setEnabled(false);
        jButtonDeleteEstate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDeleteEstateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButtonDeleteEstate)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 551, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonDeleteEstate)
                .addContainerGap())
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), bundle.getString("OWNERS OF SELECTED REAL ESTATE"))); // NOI18N

        jButtonEstateOwnersAdd.setText(bundle.getString("ADD OWNERS")); // NOI18N
        jButtonEstateOwnersAdd.setEnabled(false);
        jButtonEstateOwnersAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEstateOwnersAddActionPerformed(evt);
            }
        });

        jTableEstateOwners.setModel(new OwnershipsTableModel(false));
        jTableEstateOwners.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableEstateOwners.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTableEstateOwnersFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTableEstateOwnersFocusLost(evt);
            }
        });
        jScrollPane2.setViewportView(jTableEstateOwners);

        jButtonRemoveEstateOwnership.setText(bundle.getString("REMOVE OWNER")); // NOI18N
        jButtonRemoveEstateOwnership.setEnabled(false);
        jButtonRemoveEstateOwnership.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRemoveEstateOwnershipActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jButtonRemoveEstateOwnership)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonEstateOwnersAdd)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonEstateOwnersAdd)
                    .addComponent(jButtonRemoveEstateOwnership))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanelEstatesLayout = new javax.swing.GroupLayout(jPanelEstates);
        jPanelEstates.setLayout(jPanelEstatesLayout);
        jPanelEstatesLayout.setHorizontalGroup(
            jPanelEstatesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelEstatesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelEstatesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelEstatesLayout.setVerticalGroup(
            jPanelEstatesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelEstatesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelEstatesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelEstatesLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane4.addTab(bundle.getString("TAB ESTATES"), jPanelEstates); // NOI18N

        jMenu1.setText(bundle.getString("FILE")); // NOI18N

        jMenuItemQuit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemQuit.setText(bundle.getString("QUIT")); // NOI18N
        jMenuItemQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemQuitActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItemQuit);

        jMenuBar1.add(jMenu1);

        jMenuAbout.setText(bundle.getString("ABOUT")); // NOI18N

        jMenuItem1.setText(bundle.getString("JMENUITEM1")); // NOI18N
        jMenuAbout.add(jMenuItem1);

        jMenuBar1.add(jMenuAbout);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane4)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane4)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItemQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemQuitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItemQuitActionPerformed

    private void jButtonOwnerEstatesAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOwnerEstatesAddActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SwingAddOwnerships addOwnerships = new SwingAddOwnerships(((OwnersTableModel)jTableOwners.getModel()).getOwnerAt(jTableOwners.getSelectedRow()));
                addOwnerships.setLocationRelativeTo(null);
                addOwnerships.setVisible(true);
            }
        });
    }//GEN-LAST:event_jButtonOwnerEstatesAddActionPerformed

    private void jButtonOwnerSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOwnerSaveActionPerformed
        
        boolean stopShow = false;
        
        if (jTextOwnerFieldName.getText().equals("")) {
            jTextOwnerFieldName.setToolTipText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("NAME CANNOT BE EMPTY"));
            jLabelOwnerNameErr.setForeground(Color.red);
            jLabelOwnerNameErr.setText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("!"));
            stopShow = true;
        }
        
        if (jTextOwnerFieldSurname.getText().equals("")) {
            jTextOwnerFieldSurname.setToolTipText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("SURNAME CANNOT BE EMPTY"));
            jLabelOwnerSurnameErr.setForeground(Color.red);
            jLabelOwnerSurnameErr.setText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("!"));
            stopShow = true;
        }
        
        if (jTextOwnerFieldSSN.getText().equals("")) {
            jTextOwnerFieldSSN.setToolTipText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("SSN CANNOT BE EMPTY"));
            jLabelOwnerSsnErr.setForeground(Color.red);
            jLabelOwnerSsnErr.setText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("!"));
            stopShow = true;
        }
        
        if(!stopShow) {
            if(jTextOwnerFieldId.getText().isEmpty()) {
                OwnerAddSwingWorker ownerAddSwingWorker = new OwnerAddSwingWorker(jTextOwnerFieldName.getText(), jTextOwnerFieldSurname.getText(), 
                                                                                    jTextOwnerFieldAddress.getText(), jTextOwnerFieldSSN.getText(), 
                                                                                    jTextOwnerFieldOwnerTelephone.getText(), (OwnersTableModel) jTableOwners.getModel());
                ownerAddSwingWorker.execute();
            } else {
                OwnerEditSwingWorker worker = new OwnerEditSwingWorker(jTextOwnerFieldId.getText(), jTextOwnerFieldName.getText(), 
                                                                        jTextOwnerFieldSurname.getText(), jTextOwnerFieldAddress.getText(), 
                                                                        jTextOwnerFieldSSN.getText(), jTextOwnerFieldOwnerTelephone.getText(), 
                                                                        (OwnersTableModel) jTableOwners.getModel());
                worker.execute();
            }
            
            clearOwnerTextFields();
        }
    }//GEN-LAST:event_jButtonOwnerSaveActionPerformed

    private void jTextOwnerFieldNameMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextOwnerFieldNameMouseClicked
    }//GEN-LAST:event_jTextOwnerFieldNameMouseClicked

    private void jTextOwnerFieldNameInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jTextOwnerFieldNameInputMethodTextChanged
    }//GEN-LAST:event_jTextOwnerFieldNameInputMethodTextChanged

    private void jTextOwnerFieldNameKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextOwnerFieldNameKeyTyped
    }//GEN-LAST:event_jTextOwnerFieldNameKeyTyped

    private void jTextOwnerFieldNameKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextOwnerFieldNameKeyPressed
    }//GEN-LAST:event_jTextOwnerFieldNameKeyPressed

    private void jTextOwnerFieldSurnameKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextOwnerFieldSurnameKeyPressed
    }//GEN-LAST:event_jTextOwnerFieldSurnameKeyPressed

    private void jTextOwnerFieldAddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextOwnerFieldAddressActionPerformed
    }//GEN-LAST:event_jTextOwnerFieldAddressActionPerformed

    private void jButtonDeleteOwnerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteOwnerActionPerformed
        if(jTableOwners.getSelectedRow() != -1) {
            if(jTableOwnerEstates.getRowCount() != 0) {
                JOptionPane.showMessageDialog(null, "An owner that still has some ownerships cannot be deleted");
                return;
            }
            OwnerDeleteSwingWorker worker = new OwnerDeleteSwingWorker(((OwnersTableModel) jTableOwners.getModel()).getOwnerAt(jTableOwners.getSelectedRow()), 
                                                                        (OwnersTableModel) jTableOwners.getModel());
            worker.execute();
            jButtonDeleteOwner.setEnabled(false);
            clearOwnerTextFields();
        }
    }//GEN-LAST:event_jButtonDeleteOwnerActionPerformed

    private void jTableOwnersFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTableOwnersFocusGained
        jButtonDeleteOwner.setEnabled(true);
        jButtonOwnerEstatesAdd.setEnabled(true);
    }//GEN-LAST:event_jTableOwnersFocusGained

    private void jTableOwnersFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTableOwnersFocusLost
        if(jTableOwners.getSelectedRow() == -1) {
            jButtonDeleteOwner.setEnabled(false);
            jButtonOwnerEstatesAdd.setEnabled(false);
        }
    }//GEN-LAST:event_jTableOwnersFocusLost

    private void jTableOwnersMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableOwnersMouseClicked
        int rowIndex = jTableOwners.getSelectedRow();
        OwnersTableModel model = (OwnersTableModel) jTableOwners.getModel();
        fillOwnerTextFields((String) model.getValueAt(rowIndex, 5), (String) model.getValueAt(rowIndex, 0), (String) model.getValueAt(rowIndex, 1), 
                            (String) model.getValueAt(rowIndex, 2), (String) model.getValueAt(rowIndex, 3), (String) model.getValueAt(rowIndex, 4));
        OwnershipListSwingWorker worker = new OwnershipListSwingWorker(model.getOwnerAt(rowIndex), (OwnershipsTableModel) jTableOwnerEstates.getModel());
        worker.execute();
    }//GEN-LAST:event_jTableOwnersMouseClicked

    private void jButtonClearOwnerFormActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClearOwnerFormActionPerformed
        clearOwnerTextFields();
    }//GEN-LAST:event_jButtonClearOwnerFormActionPerformed

    private void jButtonDeleteEstateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteEstateActionPerformed
        if(jTableEstates.getSelectedRow() != -1) {
            if(jTableEstateOwners.getRowCount() != 0) {
                JOptionPane.showMessageDialog(null, "An estate that still has some ownerships cannot be deleted");
                return;
            }
            EstateDeleteSwingWorker worker = new EstateDeleteSwingWorker(((EstatesTableModel) jTableEstates.getModel()).getEstateAt(jTableEstates.getSelectedRow()), 
                                                                        (EstatesTableModel) jTableEstates.getModel());
            worker.execute();
            jButtonDeleteEstate.setEnabled(false);
            clearEstateTextFields();
        }
    }//GEN-LAST:event_jButtonDeleteEstateActionPerformed

    private void jTableEstatesFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTableEstatesFocusGained
        jButtonDeleteEstate.setEnabled(true);
        jButtonEstateOwnersAdd.setEnabled(true);
    }//GEN-LAST:event_jTableEstatesFocusGained

    private void jButtonEstateSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEstateSaveActionPerformed
        boolean stopShow = false;
        
        if (jTextFieldEstateCatastralID.getText().equals("")) {
            jTextOwnerFieldSurname.setToolTipText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("CATASTRALID CANNOT BE EMPTY"));
            jLabelEstateCatastralIDErr.setForeground(Color.red);
            jLabelEstateCatastralIDErr.setText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("!"));
            stopShow = true;
        }
        
        if (jTextFieldEstateAddress.getText().equals("")) {
            jTextOwnerFieldName.setToolTipText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("ADDRESS CANNOT BE EMPTY"));
            jLabelEstateAddressErr.setForeground(Color.red);
            jLabelEstateAddressErr.setText(java.util.ResourceBundle.getBundle("cz/muni/fi/pv168/uloha3/swing/properties/SwingGuiMain", localization).getString("!"));
            stopShow = true;
        }
        
        if(!stopShow) {
            if(jTextFieldEstateId.getText().isEmpty()) {
                EstateAddSwingWorker estateAddSwingWorker = new EstateAddSwingWorker(jTextFieldEstateCatastralID.getText(), jTextFieldEstateAddress.getText(), 
                                                                                     jComboBoxEstateType.getSelectedItem().toString(), (EstatesTableModel) jTableEstates.getModel());
                estateAddSwingWorker.execute();
            } else {
                EstateEditSwingWorker worker = new EstateEditSwingWorker(jTextFieldEstateId.getText(), jTextFieldEstateCatastralID.getText(), 
                                                                         jTextFieldEstateAddress.getText(), jComboBoxEstateType.getSelectedItem().toString(), 
                                                                         (EstatesTableModel) jTableEstates.getModel());
                worker.execute();
            }
            
            clearEstateTextFields();
        }
    }//GEN-LAST:event_jButtonEstateSaveActionPerformed

    private void jButtonClearEstateFormActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClearEstateFormActionPerformed
        clearEstateTextFields();
    }//GEN-LAST:event_jButtonClearEstateFormActionPerformed

    private void jTableEstatesFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTableEstatesFocusLost
        if(jTableEstates.getSelectedRow() == -1) {
            jButtonDeleteEstate.setEnabled(false);
            jButtonEstateOwnersAdd.setEnabled(false);
        }
    }//GEN-LAST:event_jTableEstatesFocusLost

    private void jTableEstatesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableEstatesMouseClicked
        int rowIndex = jTableEstates.getSelectedRow();
        EstatesTableModel model = (EstatesTableModel) jTableEstates.getModel();
        fillEstateTextFields((String) model.getValueAt(rowIndex, 3), (String) model.getValueAt(rowIndex, 0), 
                            (String) model.getValueAt(rowIndex, 1), (String) model.getValueAt(rowIndex, 2));
        OwnershipListSwingWorker worker = new OwnershipListSwingWorker(((EstatesTableModel) jTableEstates.getModel()).getEstateAt(rowIndex), (OwnershipsTableModel) jTableEstateOwners.getModel());
        worker.execute();
    }//GEN-LAST:event_jTableEstatesMouseClicked

    private void jButtonRemoveUserOwnershipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoveUserOwnershipActionPerformed
        int rowIndex = jTableOwnerEstates.getSelectedRow();
        OwnershipsTableModel model = (OwnershipsTableModel) jTableOwnerEstates.getModel();
        OwnershipRemoveSwingWorker worker = new OwnershipRemoveSwingWorker(model.getOwnershipAt(rowIndex), (OwnershipsTableModel) jTableOwnerEstates.getModel(), (OwnershipsTableModel) jTableEstateOwners.getModel());
        worker.execute();
    }//GEN-LAST:event_jButtonRemoveUserOwnershipActionPerformed

    private void jButtonRemoveEstateOwnershipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoveEstateOwnershipActionPerformed
        int rowIndex = jTableEstateOwners.getSelectedRow();
        OwnershipsTableModel model = (OwnershipsTableModel) jTableEstateOwners.getModel();
        OwnershipRemoveSwingWorker worker = new OwnershipRemoveSwingWorker(model.getOwnershipAt(rowIndex), (OwnershipsTableModel) jTableOwnerEstates.getModel(), (OwnershipsTableModel) jTableEstateOwners.getModel());
        worker.execute();
    }//GEN-LAST:event_jButtonRemoveEstateOwnershipActionPerformed

    private void jTableOwnerEstatesFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTableOwnerEstatesFocusGained
        jButtonRemoveUserOwnership.setEnabled(true);
    }//GEN-LAST:event_jTableOwnerEstatesFocusGained

    private void jTableOwnerEstatesFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTableOwnerEstatesFocusLost
        if(jTableOwnerEstates.getSelectedRow() == -1) {
            jButtonRemoveUserOwnership.setEnabled(false);
        }
    }//GEN-LAST:event_jTableOwnerEstatesFocusLost

    private void jTableEstateOwnersFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTableEstateOwnersFocusGained
        jButtonRemoveEstateOwnership.setEnabled(true);
    }//GEN-LAST:event_jTableEstateOwnersFocusGained

    private void jTableEstateOwnersFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTableEstateOwnersFocusLost
        if(jTableEstateOwners.getSelectedRow() == -1) {
            jButtonRemoveEstateOwnership.setEnabled(false);
        }
    }//GEN-LAST:event_jTableEstateOwnersFocusLost

    private void jButtonEstateOwnersAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEstateOwnersAddActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SwingAddOwnerships addEstates = new SwingAddOwnerships(((EstatesTableModel)jTableEstates.getModel()).getEstateAt(jTableEstates.getSelectedRow()));
                addEstates.setLocationRelativeTo(null);
                addEstates.setVisible(true);
            }
        });
    }//GEN-LAST:event_jButtonEstateOwnersAddActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SwingGuiMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SwingGuiMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SwingGuiMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SwingGuiMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SwingGuiMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonClearEstateForm;
    private javax.swing.JButton jButtonClearOwnerForm;
    private javax.swing.JButton jButtonDeleteEstate;
    private javax.swing.JButton jButtonDeleteOwner;
    private javax.swing.JButton jButtonEstateOwnersAdd;
    private javax.swing.JButton jButtonEstateSave;
    private javax.swing.JButton jButtonOwnerEstatesAdd;
    private javax.swing.JButton jButtonOwnerSave;
    private javax.swing.JButton jButtonRemoveEstateOwnership;
    private javax.swing.JButton jButtonRemoveUserOwnership;
    private javax.swing.JComboBox jComboBoxEstateType;
    private javax.swing.JLabel jLabelEstateAddress;
    private javax.swing.JLabel jLabelEstateAddressErr;
    private javax.swing.JLabel jLabelEstateCatastralID;
    private javax.swing.JLabel jLabelEstateCatastralIDErr;
    private javax.swing.JLabel jLabelEstateType;
    private javax.swing.JLabel jLabelOwnerAddress;
    private javax.swing.JLabel jLabelOwnerName;
    private javax.swing.JLabel jLabelOwnerNameErr;
    private javax.swing.JLabel jLabelOwnerSSN;
    private javax.swing.JLabel jLabelOwnerSsnErr;
    private javax.swing.JLabel jLabelOwnerSurname;
    private javax.swing.JLabel jLabelOwnerSurnameErr;
    private javax.swing.JLabel jLabelOwnerTelephone;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenuAbout;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItemQuit;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanelEstates;
    private javax.swing.JPanel jPanelOwners;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane4;
    private javax.swing.JTable jTableEstateOwners;
    private javax.swing.JTable jTableEstates;
    private javax.swing.JTable jTableOwnerEstates;
    private javax.swing.JTable jTableOwners;
    private javax.swing.JTextField jTextFieldEstateAddress;
    private javax.swing.JTextField jTextFieldEstateCatastralID;
    private javax.swing.JTextField jTextFieldEstateId;
    private javax.swing.JTextField jTextOwnerFieldAddress;
    private javax.swing.JTextField jTextOwnerFieldId;
    private javax.swing.JTextField jTextOwnerFieldName;
    private javax.swing.JTextField jTextOwnerFieldOwnerTelephone;
    private javax.swing.JTextField jTextOwnerFieldSSN;
    private javax.swing.JTextField jTextOwnerFieldSurname;
    // End of variables declaration//GEN-END:variables

    
    private void clearOwnerTextFields() {
        fillOwnerTextFields(null, null, null, null, null, null);
    }
    private void fillOwnerTextFields(String id, String name, String surename, String ssn, String address, String telephone) {
        jTextOwnerFieldId.setText(id);
        jTextOwnerFieldName.setText(name);
        jTextOwnerFieldSurname.setText(surename);
        jTextOwnerFieldSSN.setText(ssn);
        jTextOwnerFieldAddress.setText(address);
        jTextOwnerFieldOwnerTelephone.setText(telephone);
        jLabelOwnerNameErr.setText("");
        jLabelOwnerSurnameErr.setText("");
        jLabelOwnerSsnErr.setText("");
    }
    
    private void clearEstateTextFields() {
        fillEstateTextFields(null, null, null, null);
    }
    private void fillEstateTextFields(String id, String catastralId, String address, String type) {
        jTextFieldEstateCatastralID.setText(catastralId);
        jTextFieldEstateAddress.setText(address);
        jComboBoxEstateType.setSelectedItem(type);
        jTextFieldEstateId.setText(id);
        jLabelEstateCatastralIDErr.setText("");
        jLabelEstateAddressErr.setText("");
    }
}
